function e = findElipse2( M )
%FINDELIPSE2 najde elipsu, ktera nejvic odpovida oblasti v bin. obrazku M
%           e elipsa ve tvaru:
%             e(1)x^2 + e(2)xy + e(3)y^2 + e(4)x + e(5)y + e(6) = 0

[SizeY, SizeX] = size(M);
[x,y,done] = borders(M);
e = bestfitelipse(x,y);
for r = 8:-2:2
    e = straightenElipse(e, 1.0-0.11*r);
    Me = elipseMask(SizeX, SizeY, e);
    se = strel('disk', r);
    Mi = imerode(Me, se);
    Mo = imdilate(Me, se);
    M = (M | Mi) & Mo;
    [x,y,done] = borders(M);
    e = bestfitelipse(x,y);
end

